<?php
/**
 * Created by PhpStorm.
 * User: 28395
 * Date: 2017/1/6
 * Time: 22:11
 */
require 'common.inc.php';

if($_POST) extract($_POST, EXTR_SKIP);//解析post请求的数据


if (!$MQG && $_POST) {
	$_POST = daddslashes($_POST);
}
if (!$MQG && $_GET) {
	$_GET = daddslashes($_GET);
}
if ($_POST) {
	extract($_POST, EXTR_SKIP);
}
//解析post请求的数据
if ($_GET) {
	extract($_GET, EXTR_SKIP);
}

//$s_email; //传递过来的邮箱

//$mode ; //传递过来的模式  1 = 只有微信推送；  2= 只有邮件推送；   3= 微信+邮件推送；

set_cookie('mobile', 'pc', $DT_TIME + 30 * 86400);
$openid = decrypt(get_cookie('weixin_openid'), DT_KEY.'WXID');
if(!empty($s_email)){
	$db->query("UPDATE {$DT_PRE}weixin_user SET email='$s_email' WHERE openid = '$openid'");	
}

$flag = 'y';
switch ($mode) {
	case '1':
	 	$db->query("UPDATE {$DT_PRE}weixin_user SET pushwx='1',pushemail='0' WHERE openid = '$openid'");	
		break;
	case '2':
		$db->query("UPDATE {$DT_PRE}weixin_user SET pushwx='0',pushemail='1' WHERE openid = '$openid'");	
		break;
	case '3':
		$db->query("UPDATE {$DT_PRE}weixin_user SET pushwx='1', pushemail='1' WHERE openid = '$openid'");	
		break;
	default: 
		$flag = 'n';
		break;
}

$success = true;
$error_code = 200;
$datalist =array();
$json = array('flag'=>$flag,'success' =>$success, 'error_code' =>$error_code, 'datalist' =>$openid);
echo json_encode($json);